<script>
	import route from '@/route/index.js'
	import {
		get,
		set
	} from "@/common/js/uilt/index.js"
	import {
		getdata,
		obtain
	} from "@/common/js/api/user.js"
	export default {
		globalData: {
			// getImage() {
			// 	return uniCloud.getTempFileURL({
			// 		fileList: [result.fileID]
			// 	});
			// }
			
		},

		 onLaunch: function(options) {
			route()
			this.getUserIf(options)
		},
		onShow: function() {
			// console.log('App Show')
		},
		onHide: function() {
			// console.log('App Hide')
		},
		methods:{
			async getUserIf(options){
				let type = get('uni_id_token') === options.token
				if (!type) {
					set('inviter_uid', options.token)
				}
				if(["",undefined].includes(get('uni_id_token'))){
					await obtain()
				}else if(get('uni_id_token_expired') - Date.now() < 60*1000*20){
					await obtain()
				}
				
				let res = await getdata()
				let url = res.result.userInfo.avatarUrl
				let UserInfo = {
					...res.result.userInfo
				}
				UserInfo.avatarUrl = await this.$getImg(url)
				return
				set('userInfo',UserInfo)
			},
			// async handleUser(UserInfo){
				
			// 	if(UserInfo.avatarUrl.indexOf("cloud://") != -1){
			// 		UserInfo.avatarUrl = await this.$getImg(UserInfo.avatarUrl)
			// 		return UserInfo
					
			// 	}else{
			// 		return UserInfo
			// 	}
			// }
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';
	@import "uview-ui/index.scss";
	// 设置整个项目的背景色
	@import "@/common/scss/index.scss";

	page {
		background-color: #f5f5f5;
	}

	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
</style>
